package de.hdu.myjobapp.dao;

import java.util.List;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import de.hdu.myjobapp.model.Organisation;

/**
 * Data Access class for Orgs
 */	
public class OrganisationDao extends HibernateDaoSupport{

	/**
	 * create a new Org
	 */	
	public void create(String orgName, String orgAdresse, String orgBuildnr, String orgCity, String orgZip, String orgAdressadd, String orgInfo){
		Organisation o = new Organisation();
		o.setOrgName(orgName);
		o.setOrgAdresse(orgAdresse);
		o.setOrgBuildnr(orgBuildnr);
		o.setOrgCity(orgCity);
		o.setOrgZip(orgZip);
		o.setOrgAdressadd(orgAdressadd);
		o.setOrgInfo(orgInfo);
		save(o);
	}
		
	/**
	 * Saves the new recieved Org from Method create with hibernate into database
	 */	
	public Organisation save(Organisation org){
		HibernateTemplate template = getHibernateTemplate();
		template.saveOrUpdate(org);
		return org;
	}

	/**
	 * return all existing Org
	 */	
	public List<Organisation> findAll(){
		HibernateTemplate template = getHibernateTemplate();
		return template.loadAll(Organisation.class);
	}
	
	/**
	 * Return an existing Org by naming ID
	 */	
	public Organisation findById(int id){
		HibernateTemplate template = getHibernateTemplate();
		return(Organisation) template.get(Organisation.class, id);
	}
}

